﻿@{
    ViewBag.Title = "Custome";
}

@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
        @Html.Partial("~/Views/Modular/ToolBarBaseEx.cshtml")
        @Html.Partial("~/Views/Modular/SearchInfo.cshtml")
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="GetList"
                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client">
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">编码</div>
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">客户名称</div>
                    <div field="FMobileNumber" name="FMobileNumber" width="100" headeralign="center" allowsort="true">手机号码</div>
                    <div field="FPhone" name="FPhone" width="100" headeralign="center" allowsort="true">电话号码</div>
                    <div field="FContacts" name="FContacts" width="80" headeralign="center" allowsort="true">联系人</div>
                    <div field="FAddress" name="FPhone" width="150" headeralign="center" allowsort="true">地址</div>
                    <div field="FGpbNumber" name="FGpbNumber" width="100" headeralign="center" allowsort="true">价格方案编码</div>
                    <div field="FGpbName" name="FGpbName" width="100" headeralign="center" allowsort="true">价格方案名称</div>
                    <div field="FRemark" name="FRemark" width="100" headeralign="center" allowsort="true">备注</div>
                </div>
            </div>
        </div>

<script>
    function FormShown() {
        mini.parse();
        LoadListData();
    }

    function setkeyPress() {
        LoadListData();
    }
    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            NewInfo();
        }
        else {
            $.post("GetCustom", { json: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FNumber").setValue("");
        mini.getbyName("FName").setValue("");
        mini.getbyName("FPhone").setValue("");
        mini.getbyName("FContacts").setValue("");
        mini.getbyName("FAddress").setValue("");
        mini.getbyName("FRemark").setValue("");
        var jsonstr = '{"mSystemAppID":"' + parent.window.getSystemAppID() + '"}';
        $.post('NewCustomInfo', { json: jsonstr }, function (data) {
            mini.getbyName("FNumber").setValue(data);
        });
    }

    //保存资料
    function SaveInfo() {
        //mini.getbyName("FSystemAppID").setValue(parent.window.getSystemAppID());
        //mini.getbyName("SaveInfo").enable=false;
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) {
            //mini.getbyName("SaveInfo").enable=true;
            return;
        }
        var data = form.getData(true, false);

        var json = mini.encode(data);
        $.post("SaveCustomInfo", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                NewInfo();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            //mini.getbyName("SaveInfo").enable=true;
        });
    }


    //加载资料列表
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");//==
        grid.load({ mjson: json });
    }

    //搜索资料列表
    function search() {
        LoadListData();
    }

    //刷新
    function refresh() {
        mini.getbyName("FSearchKey").setValue('');
        LoadListData();
    }

    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        mini.open({
            url: "/Custom/CustomInfo",
            title: "客户资料", width: 700, height: 300,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                var grid = mini.get("datagrid1");
                grid.reload();
            }
        });
    }

    //修改资料
    function modify() {
        if (!mini.get("edit").getVisible()) return;
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/Custom/CustomInfo",
                title: "客户资料", width: 700, height: 300,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "edit", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    //删除资料
    function removeInfo() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        var FSystemAppID = parent.window.getSystemAppID();
        if (row) {
            mini.confirm("确定删除选中记录？", "提示",
            function (action) {
                if (action == "ok") {

                    var json = "{'FItemID':'" + row.FItemID + "'}";
                    $.post("RemoveCustomInfo", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                        var ret = mini.decode(data);
                        if (ret.status == 1) {
                            grid.reload();
                        }
                        else {
                            mini.alert("异常:" + ret.error);
                        }
                    });
                }
            });
        } else {
            mini.alert("请选中一条记录");
        }
    }

</script>